package gui.parser;

import java.util.HashMap;
import java.util.Map;

public class Attr {
	private Map<String, String> attr = new HashMap<>();

	public void addAttr(String key, String value) {
		attr.put(key, value);
	}

	/**
	 * 获取整数型参数
	 * 
	 * @param key
	 * @param def
	 * @return
	 */
	public int getIntAttr(String key, int def) {
		String temp = get(key);
		if (temp != null) {
			try {
				return Integer.parseInt(temp);
			} catch (Exception e) {
			}
		}
		return def;
	}
	/**
	 * 获取boolean型参数
	 * 
	 * @param key
	 * @param def
	 * @return
	 */
	public boolean getBooleanAttr(String key, boolean def) {
		String temp = get(key);
		if (temp != null) {
			try {
				return Boolean.getBoolean(temp);
			} catch (Exception e) {
			}
		}
		return def;
	}
	public String get(String key) {
		return attr.get(key);
	}
}
